import React, { Component } from 'react';
import { Table, Pagination } from 'antd'
import styles from './TableList.less'
import { connect } from 'dva'
@connect(({ login }) => ({
  login
}))

class TableList extends Component {
  render() {
    const { ConsumerListItem, loading } = this.props
    const { isAdmin } = this.props.login
    console.log(ConsumerListItem)
    const { list, totalElements } = ConsumerListItem
    const columns = [
      {
        title: '会员名称',
        dataIndex: 'name',
        key: '2',
        width: "15%"
      },
      {
        title: '类型',
        dataIndex: 'isStore',
        key: '3',
        width: "10%",
        render: (text) => {
          return (
            <span>{text == 0 ? "会员" : "暂无"}</span>
          )
        }
      },
      {
        title: '注册时间',
        dataIndex: 'createTime',
        key: '4',
        width: "19%"
      },
      {
        title: '消费金',
        dataIndex: 'money',
        key: '5',
        width: "7%",
        render: (text) => {
          return (
            <span>{text ? text : 0}</span>
          )
        }
      },
      {
        title: '福利金',
        dataIndex: 'welfareMoney',
        key: '6',
        width: "7%",
        render: (text) => {
          return (
            <span>{text ? text : 0}</span>
          )
        }
      },
      {
        title: '积分',
        dataIndex: 'bonous',
        key: '7',
        width: "7%",
        render: (text) => {
          return (
            <span>{text ? text : 0}</span>
          )
        }
      },
      {
        title: '礼券',
        dataIndex: 'giftMoney',
        key: '8',
        width: "10%",
        render: (text) => {
          return (
            <span>{text ? text : 0}</span>
          )
        }
      },
      {
        title: '操作',
        dataIndex: 'record',
        key: '9',
        width: "20%",
        render: (text, record) => {
          return (
            <div className={styles.record}>
              {isAdmin ? <span onClick={() => this.props.onLookList(record)}>查看</span> : <span></span>}
              {isAdmin ? <span onClick={() => this.props.onOpenRecharge(record)}>会员充值</span> : <span></span>}
              <span onClick={() => this.props.onGetDetails(record)}>资金明细</span>
              {isAdmin ? <span onClick={() => this.props.onChangeToBuyer(record)}>转为商家</span> : <span></span>}
            </div>
          )

        }
      },
    ];

    const rowSelection = {
      onChange: this.props.onSelectChange,
    };

    return (
      <div className={styles.vip_TableList}>
        <Table bordered
          columns={columns}
          dataSource={list}
          loading={loading}
          rowSelection={rowSelection}
          rowKey={record => record.id}
        />

        <Pagination defaultCurrent={1} total={totalElements} onChange={this.props.onChangePage} style={{ float: 'right', marginTop: '20px' }} />
      </div>
    );
  }
}

export default TableList;

